import { ref } from 'vue'

export const useChat = () => {
    const currentUser = {
        id: 'user123',
        username: 'GameMaster',
        avatar: 'https://img.tukuppt.com/png_preview/00/52/31/gqsUON6GeI.jpg!/fw/780'
    }

    const messages = ref([
        {
            id: 'msg1',
            userId: 'user456',
            username: 'Raise',
            content: 'try评分3.0 tjs得了MVP！',
            timestamp: new Date(Date.now() - 3600000)
        }
        // 其他消息...
    ])

    const newMessage = ref('')

    const sendMessage = () => {
        if (!newMessage.value.trim()) return

        messages.value.push({
            id: `msg${Date.now()}`,
            userId: currentUser.id,
            username: currentUser.username,
            content: newMessage.value,
            avatar: currentUser.avatar,
            timestamp: new Date()
        })

        newMessage.value = ''
    }

    return { messages, newMessage, sendMessage, currentUser }
}
